#!/bin/sh

VERSION="$(cat ../version)"
TARBALL_NAME="predesys-bluetooth-proxy-$VERSION"

TMP_DIR="tmp"
OUT_DIR="output"

rm -rf $TMP_DIR
rm -rf $OUTPUT_DIR

TARBALL_DIR=$TARBALL_NAME
TARBALL_SRC_DIR="src"
TARBALL_FILE="$TARBALL_NAME.tar.gz"

SRC_DIR="src"
TARBALL_SCRIPTS_DIR="tarball"
ABOUT_FILE="about"
LICENSE_FILE="license"
CHANGELOG_FILE="changelog"
README_FILE="readme"
MAKEFILE="Makefile"

rm -rf $TMP_DIR

mkdir $TMP_DIR
mkdir $TMP_DIR/$TARBALL_DIR
mkdir $TMP_DIR/$TARBALL_DIR/$TARBALL_SRC_DIR

cp ../$SRC_DIR/*.py $TMP_DIR/$TARBALL_DIR/$TARBALL_SRC_DIR
cp ../$SRC_DIR/*.xml $TMP_DIR/$TARBALL_DIR/$TARBALL_SRC_DIR
cp ../$SRC_DIR/predesys-bluetooth-proxy $TMP_DIR/$TARBALL_DIR/$TARBALL_SRC_DIR

rm -f $TMP_DIR/$TARBALL_DIR/$TARBALL_SRC_DIR/*.pyc

cp ../$ABOUT_FILE $TMP_DIR/$TARBALL_DIR
cp ../$LICENSE_FILE $TMP_DIR/$TARBALL_DIR
cp ../$CHANGELOG_FILE $TMP_DIR/$TARBALL_DIR
cp $TARBALL_SCRIPTS_DIR/$MAKEFILE $TMP_DIR/$TARBALL_DIR
cp $TARBALL_SCRIPTS_DIR/$README_FILE $TMP_DIR/$TARBALL_DIR

cd $TMP_DIR
tar czf $TARBALL_FILE $TARBALL_DIR
cd ..

mkdir -p $OUT_DIR
cp $TMP_DIR/$TARBALL_FILE $OUT_DIR

rm -rf $TMP_DIR
